//
// Created by jsjxsy on 2022/9/1.
//vector嵌套
//
#include <vector>
#include <iostream>
using namespace std;
//
// Created by jsjxsy on 2022/9/1.
// 静态数组
//
#include <vector>
#include <iostream>
using namespace std;

void test02() {
  vector<int> v;
  for (int i = 0; i < 100000; i++) {
    v.push_back(i);
  }

  cout << "v的容量为：" << v.capacity() << endl;
  cout << "v的大小为：" << v.size() << endl;

  v.resize(3);

  cout << "v的容量为：" << v.capacity() << endl;
  cout << "v的大小为：" << v.size() << endl;

  //收缩内存
  vector<int>(v).swap(v); //匿名对象

  cout << "v的容量为：" << v.capacity() << endl;
  cout << "v的大小为：" << v.size() << endl;
}

int main() {
  vector<int> v1;
  for (int i = 5; i > 0; i--) {
    v1.push_back(i + 1);
  }

  vector<int> v2;
//  v2.resize(5, 1);
  v2.push_back(1);
  v2.push_back(2);
  v2.push_back(3);
  v2.push_back(4);
  v2.push_back(5);
  v1.swap(v2);
  for (vector<int>::iterator it = v1.begin(); it != v1.end(); it++) {
    cout << *it << " ";
  }
  cout << endl;

  for (vector<int>::iterator it = v2.begin(); it != v2.end(); it++) {
    cout << *it << " ";
  }
  cout << endl;

  test02();
  return 0;
}

